//
//  NSObject+Extension.m
//  BPTV
//
//  Created by baipeng on 2018/11/15.
//  Copyright © 2018年 Apple Inc. All rights reserved.
//

#import "NSObject+Extension.h"
#import <MBProgressHUD/MBProgressHUD.h>
#import <objc/message.h>

static const void *HUDKey = &HUDKey;

@implementation NSObject (Extension)
#pragma mark - 动态绑定HUD属性
- (MBProgressHUD *)HUD
{
    return objc_getAssociatedObject(self, HUDKey);
}
- (void)setHUD:(MBProgressHUD * _Nullable)HUD
{
    objc_setAssociatedObject(self, HUDKey, HUD, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)showHint:(NSString *)hint
{
    //显示提示信息
    UIView *view = [[UIApplication sharedApplication].delegate window];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.userInteractionEnabled = NO;
    hud.mode = MBProgressHUDModeText;
    hud.label.text = hint;
    hud.margin = 10.f;
    hud.removeFromSuperViewOnHide = YES;
    [hud hideAnimated:YES afterDelay:2];

}
- (void)showHint:(NSString *)hint inView:(UIView *)view
{
    //显示提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    [view addSubview:hud];
    hud.userInteractionEnabled = NO;
    hud.mode = MBProgressHUDModeText;
    hud.label.text = hint;
    hud.margin = 10.f;
    hud.removeFromSuperViewOnHide = YES;
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:2];
}

+(void)loadingShowHUD{
    //显示提示信息
    UIView *view = [[UIApplication sharedApplication].delegate window];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.opacity = 0.6;
    hud.margin = 25.0;
    hud.labelText = @"请等待...";
    hud.labelFont = KScalefont(16);
    hud.removeFromSuperViewOnHide = YES;
}
+(void)stopShowHUD{
    UIView *view = [[UIApplication sharedApplication].delegate window];
    [[MBProgressHUD HUDForView:view] hide:YES];
}


@end
